
import 'package:baselib/utils/keyboard_util.dart';
import 'package:baselib/utils/load_util.dart';
import 'package:baselib/utils/log_util.dart';
import 'package:baselib/utils/navigator_util.dart';
import 'package:baselib/utils/toast_util.dart';
import 'package:framelib/base/base_view_model.dart';
import 'package:framelib/config/api_config.dart';
import 'package:framelib/config/route_config.dart';
import 'package:framelib/net/baseentity.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:get/state_manager.dart';
import 'package:get/get.dart';
import 'package:module_business/module_comm/model/interest_tag_entity.dart';
import 'package:module_business/module_comm/model/user_params_model.dart';
import 'package:module_business/module_comm/service/module_comm_service.dart';

class RegisterSelectFavoriteViewModel extends BaseViewModel<ModuleCommService>{

  ModuleCommService moduleCommService;
  List<InterestTagEntity> types = [
    InterestTagEntity(name:StringUtil.instance.Sport,imgPath:DrawableUtil.instance.icon_register_Sport),
    InterestTagEntity(name:StringUtil.instance.Bodybuilding,imgPath:DrawableUtil.instance.icon_register_Bodybuilding),
    InterestTagEntity(name:StringUtil.instance.Music,imgPath:DrawableUtil.instance.icon_register_Music),
    InterestTagEntity(name:StringUtil.instance.Yoga,imgPath:DrawableUtil.instance.icon_register_Yoga),
  ];
  @override
  ModuleCommService createService() =>moduleCommService = ModuleCommService();

  onItemPressed(int index) {
    types.forEach((typeItem){
      typeItem.selected=false;
      if(typeItem.name==types[index].name)typeItem.selected=true;
    });
    update();
  }

  toStart() {
    var selectedTypes = types.where((element) => (element?.selected??false)).toList();
    if(selectedTypes.isEmpty){
      ToastUtil.toast(StringUtil.instance.Select_your_favorite_interest_tag);
      return;
    }
    UserParamsModel.instance.setFavorite(selectedTypes[0]?.name);
    NavigatorUtil.offAllByName(RouteConfig.homePage);
  }

  toSkip() {
    NavigatorUtil.offAllByName(RouteConfig.homePage);
  }
}
